﻿using Common.Exceptions;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Client;
using PaymentService.Services;
using PaymentService.Services.Dtos;
using ProductService.Services;
using ProductService.Services.Dtos;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.ObjectMapping;
using WebSite_Aggregate.Services.Dtos;

namespace ProductService.Controllers;

/// <summary>
/// 秒杀订单支付控制器(秒杀订单支付接口)
/// </summary>
[Route("ebusinessseckills/seckillorderpay")]
public class SeckillOrdePayController : AbpController
{

    public IPaymentService paymentService { get; set; }

    public SeckillOrdePayController()
    {

    }

    /// <summary>
    /// 创建秒杀订单预支付接口
    /// </summary>
    /// <param name="createSeckillOrderPrePayDto"></param>
    /// <returns></returns>
    [HttpPost("SeckillOrderPrePay")]
    public async Task<SeckillOrderPrePayDto> CreateSeckillOrderPrePay(CreateSeckillOrderPrePayDto createSeckillOrderPrePayDto)
    {
        SeckillOrderPrePayDto seckillOrderPrePayDto = ObjectMapper.Map<CreateSeckillOrderPrePayDto, SeckillOrderPrePayDto>(createSeckillOrderPrePayDto);
        return seckillOrderPrePayDto;
    }

    /// <summary>
    /// 创建秒杀订单支付接口
    /// </summary>
    /// <param name="createSeckillOrderPayDto"></param>
    /// <returns></returns>
    [HttpPost("SeckillOrderPay")]
    public async Task<SeckillOrderPayDto> CreateSeckillOrderPay(CreateSeckillOrderPayDto createSeckillOrderPayDto)
    {
        CreateOrderPayDto createOrderPayDto = ObjectMapper.Map<CreateSeckillOrderPayDto, CreateOrderPayDto>(createSeckillOrderPayDto);
        OrderPayDto orderPayDto = await paymentService.CreateOrderPayAsync(createOrderPayDto);
        SeckillOrderPayDto seckillOrderPayDto = ObjectMapper.Map<OrderPayDto, SeckillOrderPayDto>(orderPayDto);
        return seckillOrderPayDto;
    }
}
